package com.xcc.shopanim;

import android.content.DialogInterface;
import android.view.KeyEvent;

import com.xcc.shopanim.utils.TimeConstant;

import java.text.SimpleDateFormat;

public class AppConstant {
    //--------------用于拦截dialog返回按钮-------------->>>
    public static final DialogInterface.OnKeyListener onKeyListener = (dialog, keyCode, event) -> keyCode == KeyEvent.KEYCODE_BACK;

    //--------------yyyy年MM月dd日 HH:mm-------------->>>
    public static final String TimeFrom = "yyyy年MM月dd日 HH:mm";
    public static final String TimeFromEn = "MMM/dd/yyyy HH:mm";
    public static final String TimeFrom_ = "MM月dd日 HH:mm";
    public static final String TimeFrom_En = "MMM/dd HH:mm";
    public static final String TimeFrom2 = "yyyy.MM.dd HH:mm";
    public static final String TimeFrom2En = "MMM.dd.yyyy HH:mm";
    public static final String TimeFrom3 = "yyyy-MM-dd HH:mm";
    public static final String TimeFrom3En = "MMM-dd-yyyy HH:mm";
    public static final String TimeFrom4 = "MM-dd HH:mm";
    public static final String TimeFrom4En = "MMM-dd HH:mm";
    public static final String TimeFrom5 = "yyyy-MM-dd HH:mm:ss";
    public static final String TimeFrom5En = "MMM-dd-yyyy HH:mm:ss";
    public static final String TimeFrom6 = "yyyy.MM.dd HH:mm:ss";
    public static final String TimeFrom6En = "MMM.dd.yyyy HH:mm:ss";

    public static final String DayFrom = "MM月dd日";
    public static final String DayFromEn = "MMM/dd";
    public static final String DayFrom2 = "yyyy.MM.dd";
    public static final String DayFrom2En = "MMM.dd.yyyy";
    public static final String DayFrom3 = "yyyy-MM-dd";
    public static final String DayFrom3En = "MMM-dd-yyyy";
    public static final String DayFrom4 = "MM-dd";
    public static final String DayFrom4En = "MMM-dd";

    /**
     * 获取时间文本
     *
     * @param time 返回 yyyy-MM-dd
     *             昨天HH:mm
     *             HH:mm
     *             1小时前
     *             30分钟前
     *             10分钟前
     *             1分钟前
     *             刚刚
     */
    public static String getTimeMsg(long time) {
        long timeMillis = System.currentTimeMillis();
        long timelen = timeMillis - time;
        if (timelen < TimeConstant._1min) {
            return "刚刚";
        } else {
            String __fenzhongqian = "%s分钟前";
            if (timelen < TimeConstant._10min) {
                return String.format(__fenzhongqian, String.valueOf(1));
            } else if (timelen < TimeConstant._30min) {
                return String.format(__fenzhongqian, String.valueOf(10));
            } else if (timelen < TimeConstant._1H) {
                return String.format(__fenzhongqian, String.valueOf(30));
            } else if (timelen < TimeConstant._2H) {
                return "一小时前";
            } else {
                SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
                String currTimeStr = format.format(timeMillis);
                String timeStr = format.format(time);
                if (currTimeStr.equals(timeStr)) {//今天
                    format = new SimpleDateFormat("HH:mm");
                    return format.format(time);
                } else {
                    timeStr = format.format(time + TimeConstant._24H);
                    if (currTimeStr.equals(timeStr)) {//昨天
                        format = new SimpleDateFormat(" HH:mm");
                        return "昨天" + format.format(time);
                    } else {
                        format = new SimpleDateFormat(DayFrom3);
                        return format.format(time);
                    }
                }
            }
        }
    }

    /**
     * 用于图片的调试地址
     */
    public static final String ImgDebugUrl = "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=2911788854,2419966094&fm=26&gp=0.jpg";
    public static final String ImgDebugUrl2 = "https://i0.hdslb.com/bfs/archive/9040b7cdd11caf5e5c9571469faebdeab0c9694d.jpg";
    public static final String ImgDebugUrl3 = "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=2210870686,3092198346&fm=26&gp=0.jpg";
    public static final String ImgDebugUrl4 = "https://i1.hdslb.com/bfs/archive/75a484d1d43daddc8a631587aab9fbccdcf3ca2c.jpg";
    public static final String ImgDebugUrl5 = "https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=2973025270,3848348185&fm=26&gp=0.jpg";
    public static final String ImgDebugUrl6 = "https://i2.hdslb.com/bfs/archive/e1bad8a014608fd706876bdbc8e1733b107a4bfa.jpg";
    public static final String ImgDebugUrl7 = "https://i0.hdslb.com/bfs/archive/66f5ac0d4b0b4d613e3335e3b0a18edaefeda9f7.jpg";
    public static final String ImgDebugUrl8 = "https://i0.hdslb.com/bfs/archive/abaea0bd9094279c46473ac8e294997fe9c96319.jpg";
    public static final String ImgDebugUrl9 = "https://i2.hdslb.com/bfs/archive/366d73af02c3daa673b9fda184be22ba2d11849a.jpg";
    public static final String ImgDebugUrl10 = "https://i0.hdslb.com/bfs/archive/b518dc06e09855b7ae47b525da2e35cd6f9b59ea.jpg";
}